| | | 1 | | using Elsa.AI.Abstractions.Models; |
| | | 2 | | using Elsa.AI.Host.Services; |
| | | 3 | | using Elsa.AI.Host.Tools; |
| | | 4 | | using Elsa.Workflows; |
| | | 5 | | |
| | | 6 | | namespace Elsa.AI.Host.Tools.Activities; |
| | | 7 | | |
| | 45 | 8 | | public class ActivityDescriptorTool(IServiceProvider serviceProvider, ActivityGroundingSearchService searchService, AIGr |
| | | 9 | | { |
| | 90 | 10 | | public override AIToolDefinition Definition { get; } = ReadOnlyDefinition( |
| | 45 | 11 | | "activities.getDescriptor", |
| | 45 | 12 | | "Get activity descriptor", |
| | 45 | 13 | | "Get model-safe metadata for one installed activity descriptor.", |
| | 45 | 14 | | GroundingToolSchemas.WithProperties( |
| | 45 | 15 | | ("type", GroundingToolSchemas.String("Activity type name or short name.")), |
| | 45 | 16 | | ("version", GroundingToolSchemas.Integer("Optional activity version.")))); |
| | | 17 | | |
| | | 18 | | public override ValueTask<AIToolResult> ExecuteAsync(AIToolExecutionContext context, CancellationToken cancellationT |
| | | 19 | | { |
| | 0 | 20 | | var registry = serviceProvider.GetService(typeof(IActivityRegistry)) as IActivityRegistry; |
| | 0 | 21 | | if (registry == null) |
| | 0 | 22 | | return ValueTask.FromResult(formatter.Unavailable("Activity Registry")); |
| | | 23 | | |
| | 0 | 24 | | var type = GetString(context.Arguments, "type"); |
| | 0 | 25 | | var version = GetInt(context.Arguments, "version"); |
| | 0 | 26 | | var descriptor = string.IsNullOrWhiteSpace(type) |
| | 0 | 27 | | ? null |
| | 0 | 28 | | : version != null |
| | 0 | 29 | | ? registry.Find(type, version.Value) |
| | 0 | 30 | | : registry.Find(x => string.Equals(x.TypeName, type, StringComparison.OrdinalIgnoreCase) || string.Equal |
| | | 31 | | |
| | 0 | 32 | | if (descriptor == null) |
| | 0 | 33 | | return ValueTask.FromResult(new AIToolResult { Status = AIToolInvocationStatus.Failed, Error = $"Activity '{ |
| | | 34 | | |
| | 0 | 35 | | return ValueTask.FromResult(formatter.CreateResult($"Resolved descriptor for {descriptor.TypeName} v{descriptor. |
| | | 36 | | } |
| | | 37 | | } |