| | | 1 | | using Elsa.AI.Abstractions.Models; |
| | | 2 | | using Elsa.AI.Host.Services; |
| | | 3 | | |
| | | 4 | | namespace Elsa.AI.Host.Tools.Runtime; |
| | | 5 | | |
| | 45 | 6 | | public class WorkflowInstanceTool(IServiceProvider serviceProvider, RuntimeGroundingMapper mapper, AIGroundingResultForm |
| | | 7 | | { |
| | 90 | 8 | | public override AIToolDefinition Definition { get; } = ReadOnlyDefinition( |
| | 45 | 9 | | "instances.get", |
| | 45 | 10 | | "Get workflow instance", |
| | 45 | 11 | | "Get a redacted workflow instance summary and bounded state evidence.", |
| | 45 | 12 | | GroundingToolSchemas.WithProperties( |
| | 45 | 13 | | ("instanceId", GroundingToolSchemas.String("Workflow instance ID.")), |
| | 45 | 14 | | ("id", GroundingToolSchemas.String("Workflow instance ID.")))); |
| | | 15 | | |
| | | 16 | | public override async ValueTask<AIToolResult> ExecuteAsync(AIToolExecutionContext context, CancellationToken cancell |
| | | 17 | | { |
| | 0 | 18 | | if (WorkflowInstanceStore == null) |
| | 0 | 19 | | return InstanceStoreUnavailable(); |
| | | 20 | | |
| | 0 | 21 | | var instance = await FindAuthorizedInstanceAsync(context.Arguments, context.TenantId, cancellationToken); |
| | 0 | 22 | | if (instance == null) |
| | 0 | 23 | | return new AIToolResult { Status = AIToolInvocationStatus.Failed, Error = "Workflow instance was not found." |
| | | 24 | | |
| | 0 | 25 | | var item = AIGroundingJson.ToJsonObject(mapper.Map(instance)); |
| | 0 | 26 | | item["state"] = mapper.MapState(instance); |
| | | 27 | | |
| | 0 | 28 | | return Formatter.CreateResult($"Resolved workflow instance {instance.Id}.", [item], 1, ["WorkflowInstanceStore"] |
| | 0 | 29 | | } |
| | | 30 | | } |