From 86998d9e765afc1ba3a8fd0f7d032aad59a13eb1 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 28 Mar 2026 09:11:47 +0800 Subject: [PATCH 1/3] feat(ai): Adjust the length of the description field for the tool --- ...ujst-AITool-Description-Length.Designer.cs | 383 ++++++++++++++++++ ...14905_Adjujst-AITool-Description-Length.cs | 40 ++ ...ServiceMigrationsDbContextModelSnapshot.cs | 4 +- .../Tools/AIToolDefinitionRecordConsts.cs | 2 +- 4 files changed, 426 insertions(+), 3 deletions(-) create mode 100644 aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/20260327114905_Adjujst-AITool-Description-Length.Designer.cs create mode 100644 aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/20260327114905_Adjujst-AITool-Description-Length.cs diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/20260327114905_Adjujst-AITool-Description-Length.Designer.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/20260327114905_Adjujst-AITool-Description-Length.Designer.cs new file mode 100644 index 000000000..be79dbc8c --- /dev/null +++ b/aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/20260327114905_Adjujst-AITool-Description-Length.Designer.cs @@ -0,0 +1,383 @@ +// +using System; +using LINGYUN.Abp.MicroService.AIService; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Volo.Abp.EntityFrameworkCore; + +#nullable disable + +namespace LINGYUN.Abp.MicroService.AIService.Migrations +{ + [DbContext(typeof(AIServiceMigrationsDbContext))] + [Migration("20260327114905_Adjujst-AITool-Description-Length")] + partial class AdjujstAIToolDescriptionLength + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("_Abp_DatabaseProvider", EfCoreDatabaseProvider.PostgreSql) + .HasAnnotation("ProductVersion", "10.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("LINGYUN.Abp.AIManagement.Chats.ConversationRecord", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("uuid") + .HasColumnName("CreatorId"); + + b.Property("ExpiredAt") + .HasColumnType("timestamp with time zone"); + + b.Property("LastModificationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnType("uuid") + .HasColumnName("LastModifierId"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("TenantId") + .HasColumnType("uuid") + .HasColumnName("TenantId"); + + b.Property("UpdateAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Workspace") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.HasKey("Id"); + + b.ToTable("AbpAIConversations", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.AIManagement.Chats.TextChatMessageRecord", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("Content") + .IsRequired() + .HasMaxLength(1024) + .HasColumnType("character varying(1024)"); + + b.Property("ConversationId") + .HasColumnType("uuid"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("uuid") + .HasColumnName("CreatorId"); + + b.Property("ExtraProperties") + .IsRequired() + .HasColumnType("text") + .HasColumnName("ExtraProperties"); + + b.Property("LastModificationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnType("uuid") + .HasColumnName("LastModifierId"); + + b.Property("ReplyAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ReplyMessage") + .HasColumnType("text"); + + b.Property("Role") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("TenantId") + .HasColumnType("uuid") + .HasColumnName("TenantId"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("Workspace") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "ConversationId"); + + b.ToTable("AbpAITextChatMessages", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.AIManagement.Tokens.TokenUsageRecord", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("CachedInputTokenCount") + .HasColumnType("bigint"); + + b.Property("ConversationId") + .HasColumnType("uuid"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("uuid") + .HasColumnName("CreatorId"); + + b.Property("InputTokenCount") + .HasColumnType("bigint"); + + b.Property("LastModificationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnType("uuid") + .HasColumnName("LastModifierId"); + + b.Property("MessageId") + .HasColumnType("uuid"); + + b.Property("OutputTokenCount") + .HasColumnType("bigint"); + + b.Property("ReasoningTokenCount") + .HasColumnType("bigint"); + + b.Property("TenantId") + .HasColumnType("uuid") + .HasColumnName("TenantId"); + + b.Property("TotalTokenCount") + .HasColumnType("bigint"); + + b.HasKey("Id"); + + b.HasIndex("TenantId", "ConversationId"); + + b.ToTable("AbpAITokenUsages", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.AIManagement.Tools.AIToolDefinitionRecord", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("uuid") + .HasColumnName("CreatorId"); + + b.Property("Description") + .HasMaxLength(1024) + .HasColumnType("character varying(1024)"); + + b.Property("ExtraProperties") + .IsRequired() + .HasColumnType("text") + .HasColumnName("ExtraProperties"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("IsGlobal") + .HasColumnType("boolean"); + + b.Property("IsSystem") + .HasColumnType("boolean"); + + b.Property("LastModificationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnType("uuid") + .HasColumnName("LastModifierId"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Provider") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("StateCheckers") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("AbpAIAIToolDefinitionRecords", (string)null); + }); + + modelBuilder.Entity("LINGYUN.Abp.AIManagement.Workspaces.WorkspaceDefinitionRecord", b => + { + b.Property("Id") + .HasColumnType("uuid"); + + b.Property("ApiBaseUrl") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("ApiKey") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .IsRequired() + .HasMaxLength(40) + .HasColumnType("character varying(40)") + .HasColumnName("ConcurrencyStamp"); + + b.Property("CreationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("CreationTime"); + + b.Property("CreatorId") + .HasColumnType("uuid") + .HasColumnName("CreatorId"); + + b.Property("Description") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("DisplayName") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("ExtraProperties") + .IsRequired() + .HasColumnType("text") + .HasColumnName("ExtraProperties"); + + b.Property("FrequencyPenalty") + .HasColumnType("real"); + + b.Property("Instructions") + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.Property("IsEnabled") + .HasColumnType("boolean"); + + b.Property("IsSystem") + .HasColumnType("boolean"); + + b.Property("LastModificationTime") + .HasColumnType("timestamp with time zone") + .HasColumnName("LastModificationTime"); + + b.Property("LastModifierId") + .HasColumnType("uuid") + .HasColumnName("LastModifierId"); + + b.Property("MaxOutputTokens") + .HasColumnType("integer"); + + b.Property("ModelName") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("PresencePenalty") + .HasColumnType("real"); + + b.Property("Provider") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("StateCheckers") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("SystemPrompt") + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.Property("Temperature") + .HasColumnType("real"); + + b.Property("Tools") + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.HasKey("Id"); + + b.HasIndex("Name") + .IsUnique(); + + b.ToTable("AbpAIWorkspaceDefinitions", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/20260327114905_Adjujst-AITool-Description-Length.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/20260327114905_Adjujst-AITool-Description-Length.cs new file mode 100644 index 000000000..87096d709 --- /dev/null +++ b/aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/20260327114905_Adjujst-AITool-Description-Length.cs @@ -0,0 +1,40 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace LINGYUN.Abp.MicroService.AIService.Migrations +{ + /// + public partial class AdjujstAIToolDescriptionLength : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Description", + table: "AbpAIAIToolDefinitionRecords", + type: "character varying(1024)", + maxLength: 1024, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(128)", + oldMaxLength: 128, + oldNullable: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Description", + table: "AbpAIAIToolDefinitionRecords", + type: "character varying(128)", + maxLength: 128, + nullable: true, + oldClrType: typeof(string), + oldType: "character varying(1024)", + oldMaxLength: 1024, + oldNullable: true); + } + } +} diff --git a/aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/AIServiceMigrationsDbContextModelSnapshot.cs b/aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/AIServiceMigrationsDbContextModelSnapshot.cs index 6146ee94a..3edded63e 100644 --- a/aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/AIServiceMigrationsDbContextModelSnapshot.cs +++ b/aspnet-core/aspire/LINGYUN.Abp.MicroService.AIService.EntityFrameworkCore/Migrations/AIServiceMigrationsDbContextModelSnapshot.cs @@ -221,8 +221,8 @@ namespace LINGYUN.Abp.MicroService.AIService.Migrations .HasColumnName("CreatorId"); b.Property("Description") - .HasMaxLength(128) - .HasColumnType("character varying(128)"); + .HasMaxLength(1024) + .HasColumnType("character varying(1024)"); b.Property("ExtraProperties") .IsRequired() diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionRecordConsts.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionRecordConsts.cs index 883809c66..e0289f820 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionRecordConsts.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AIManagement.Domain.Shared/LINGYUN/Abp/AIManagement/Tools/AIToolDefinitionRecordConsts.cs @@ -3,6 +3,6 @@ public static class AIToolDefinitionRecordConsts { public static int MaxNameLength { get; set; } = 64; public static int MaxProviderLength { get; set; } = 20; - public static int MaxDescriptionLength { get; set; } = 128; + public static int MaxDescriptionLength { get; set; } = 1024; public static int MaxStateCheckersLength { get; set; } = 256; } From 571be60e55158f95d0bb2018eb2b372bf05fe1df Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 28 Mar 2026 09:12:43 +0800 Subject: [PATCH 2/3] feat(ai): The MCP tool does not interfere with the operation of other tools. --- .../Abp/AI/Tools/Mcp/McpAIToolProvider.cs | 61 +++++++++++-------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Tools.Mcp/LINGYUN/Abp/AI/Tools/Mcp/McpAIToolProvider.cs b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Tools.Mcp/LINGYUN/Abp/AI/Tools/Mcp/McpAIToolProvider.cs index 29b905a7d..e9ba2bd10 100644 --- a/aspnet-core/modules/ai/LINGYUN.Abp.AI.Tools.Mcp/LINGYUN/Abp/AI/Tools/Mcp/McpAIToolProvider.cs +++ b/aspnet-core/modules/ai/LINGYUN.Abp.AI.Tools.Mcp/LINGYUN/Abp/AI/Tools/Mcp/McpAIToolProvider.cs @@ -1,6 +1,7 @@ using LINGYUN.Abp.AI.Localization; using Microsoft.Extensions.AI; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using ModelContextProtocol.Client; using System; using System.Collections.Generic; @@ -61,37 +62,47 @@ public class McpAIToolProvider : IAIToolProvider, ITransientDependency public async virtual Task CreateToolsAsync(AIToolDefinition definition) { - var httpClient = HttpClientFactory.CreateMcpAIToolClient(); - var httpClientTransportOptions = new HttpClientTransportOptions + try { - Endpoint = new Uri(definition.GetMcpEndpoint()), - AdditionalHeaders = new Dictionary(), - TransportMode = definition.GetMcpTransportMode(), - ConnectionTimeout = definition.GetMcpConnectionTimeout(), - MaxReconnectionAttempts = definition.GetMcpMaxReconnectionAttempts(), - }; - - var headers = definition.GetMcpHeaders(); - foreach (var header in headers) - { - httpClientTransportOptions.AdditionalHeaders.TryAdd(header.Key, header.Value); - } + var httpClient = HttpClientFactory.CreateMcpAIToolClient(); + var httpClientTransportOptions = new HttpClientTransportOptions + { + Endpoint = new Uri(definition.GetMcpEndpoint()), + AdditionalHeaders = new Dictionary(), + TransportMode = definition.GetMcpTransportMode(), + ConnectionTimeout = definition.GetMcpConnectionTimeout(), + MaxReconnectionAttempts = definition.GetMcpMaxReconnectionAttempts(), + }; - if (definition.IsUseMcpCurrentAccessToken()) - { - var accessTokenProvider = ServiceProvider.GetRequiredService(); + var headers = definition.GetMcpHeaders(); + foreach (var header in headers) + { + httpClientTransportOptions.AdditionalHeaders.TryAdd(header.Key, header.Value); + } - var token = await accessTokenProvider.GetTokenAsync(); - if (!token.IsNullOrWhiteSpace()) + if (definition.IsUseMcpCurrentAccessToken()) { - // TODO: 使用OAuth配置? - httpClientTransportOptions.AdditionalHeaders.TryAdd("Authorization", $"Bearer {token}"); + var accessTokenProvider = ServiceProvider.GetRequiredService(); + + var token = await accessTokenProvider.GetTokenAsync(); + if (!token.IsNullOrWhiteSpace()) + { + // TODO: 使用OAuth配置? + httpClientTransportOptions.AdditionalHeaders.TryAdd("Authorization", $"Bearer {token}"); + } } - } - var mcpClient = await McpClient.CreateAsync( - new HttpClientTransport(httpClientTransportOptions, httpClient)); + var mcpClient = await McpClient.CreateAsync( + new HttpClientTransport(httpClientTransportOptions, httpClient)); - return (await mcpClient.ListToolsAsync()).ToArray(); + return (await mcpClient.ListToolsAsync()).ToArray(); + } + catch (Exception ex) + { + ServiceProvider + .GetService>() + ?.LogWarning(ex, "Mcp tool connection failed: {message}", ex.Message); + return []; + } } } From 207421a5a4e6d087b7ab5951cb0a7133c8675507 Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 28 Mar 2026 09:13:58 +0800 Subject: [PATCH 3/3] feat: Optimization ai tool component --- .../components/tools/AIToolDefinitionModal.vue | 15 ++++++++++++--- .../localizable-input/LocalizableInput.vue | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/vben5/packages/@abp/ai-management/src/components/tools/AIToolDefinitionModal.vue b/apps/vben5/packages/@abp/ai-management/src/components/tools/AIToolDefinitionModal.vue index c57c89f80..3e885c2ff 100644 --- a/apps/vben5/packages/@abp/ai-management/src/components/tools/AIToolDefinitionModal.vue +++ b/apps/vben5/packages/@abp/ai-management/src/components/tools/AIToolDefinitionModal.vue @@ -1,5 +1,6 @@