| | | 1 | | using Elsa.AI.Abstractions.Models; |
| | | 2 | | using Elsa.AI.Host.Services; |
| | | 3 | | |
| | | 4 | | namespace Elsa.AI.Host.Tools.Workflows; |
| | | 5 | | |
| | 45 | 6 | | public class WorkflowDefinitionTool(IServiceProvider serviceProvider, WorkflowGroundingMapper mapper, AIGroundingResultF |
| | | 7 | | { |
| | 90 | 8 | | public override AIToolDefinition Definition { get; } = ReadOnlyDefinition( |
| | 45 | 9 | | "workflows.getDefinition", |
| | 45 | 10 | | "Get workflow definition", |
| | 45 | 11 | | "Get a model-safe workflow definition summary with version metadata and graph hints.", |
| | 45 | 12 | | GroundingToolSchemas.WithProperties( |
| | 45 | 13 | | ("id", GroundingToolSchemas.String("Workflow definition version ID.")), |
| | 45 | 14 | | ("versionId", GroundingToolSchemas.String("Workflow definition version ID.")), |
| | 45 | 15 | | ("definitionId", GroundingToolSchemas.String("Logical workflow definition ID.")), |
| | 45 | 16 | | ("version", GroundingToolSchemas.Integer("Specific workflow version.")), |
| | 45 | 17 | | ("published", GroundingToolSchemas.Boolean("Resolve the published version instead of the latest version."))) |
| | | 18 | | |
| | | 19 | | public override async ValueTask<AIToolResult> ExecuteAsync(AIToolExecutionContext context, CancellationToken cancell |
| | | 20 | | { |
| | 0 | 21 | | var store = WorkflowDefinitionStore; |
| | 0 | 22 | | if (store == null) |
| | 0 | 23 | | return WorkflowStoreUnavailable(); |
| | | 24 | | |
| | 0 | 25 | | var definition = await store.FindAsync(CreateDefinitionFilter(context.Arguments), cancellationToken); |
| | 0 | 26 | | if (definition == null || !IsTenantAllowed(definition, context.TenantId)) |
| | 0 | 27 | | return new AIToolResult { Status = AIToolInvocationStatus.Failed, Error = "Workflow definition was not found |
| | | 28 | | |
| | 0 | 29 | | return Formatter.CreateResult($"Resolved workflow definition {definition.DefinitionId} v{definition.Version}.", |
| | 0 | 30 | | } |
| | | 31 | | } |