| | | 1 | | using Elsa.AI.Abstractions.Models; |
| | | 2 | | using Elsa.Workflows.Management.Entities; |
| | | 3 | | using Elsa.Workflows.Management.Models; |
| | | 4 | | using Elsa.Workflows.Models; |
| | | 5 | | |
| | | 6 | | namespace Elsa.AI.Host.Services; |
| | | 7 | | |
| | 48 | 8 | | public class RuntimeGroundingMapper(AIGroundingResultFormatter formatter) |
| | | 9 | | { |
| | | 10 | | public RuntimeInstanceGroundingSummary Map(WorkflowInstanceSummary summary) => |
| | 0 | 11 | | new() |
| | 0 | 12 | | { |
| | 0 | 13 | | Id = summary.Id, |
| | 0 | 14 | | TenantId = summary.TenantId, |
| | 0 | 15 | | DefinitionId = summary.DefinitionId, |
| | 0 | 16 | | DefinitionVersionId = summary.DefinitionVersionId, |
| | 0 | 17 | | Version = summary.Version, |
| | 0 | 18 | | Status = summary.Status.ToString(), |
| | 0 | 19 | | SubStatus = summary.SubStatus.ToString(), |
| | 0 | 20 | | CorrelationId = summary.CorrelationId, |
| | 0 | 21 | | Name = summary.Name, |
| | 0 | 22 | | IncidentCount = summary.IncidentCount, |
| | 0 | 23 | | CreatedAt = summary.CreatedAt, |
| | 0 | 24 | | UpdatedAt = summary.UpdatedAt, |
| | 0 | 25 | | FinishedAt = summary.FinishedAt |
| | 0 | 26 | | }; |
| | | 27 | | |
| | | 28 | | public RuntimeInstanceGroundingSummary Map(WorkflowInstance instance) => |
| | 0 | 29 | | new() |
| | 0 | 30 | | { |
| | 0 | 31 | | Id = instance.Id, |
| | 0 | 32 | | TenantId = instance.TenantId, |
| | 0 | 33 | | DefinitionId = instance.DefinitionId, |
| | 0 | 34 | | DefinitionVersionId = instance.DefinitionVersionId, |
| | 0 | 35 | | Version = instance.Version, |
| | 0 | 36 | | Status = instance.Status.ToString(), |
| | 0 | 37 | | SubStatus = instance.SubStatus.ToString(), |
| | 0 | 38 | | CorrelationId = instance.CorrelationId, |
| | 0 | 39 | | Name = instance.Name, |
| | 0 | 40 | | IncidentCount = instance.IncidentCount, |
| | 0 | 41 | | CreatedAt = instance.CreatedAt, |
| | 0 | 42 | | UpdatedAt = instance.UpdatedAt, |
| | 0 | 43 | | FinishedAt = instance.FinishedAt |
| | 0 | 44 | | }; |
| | | 45 | | |
| | | 46 | | public IncidentGroundingSummary MapIncident(string workflowInstanceId, ActivityIncident incident) => |
| | 1 | 47 | | new() |
| | 1 | 48 | | { |
| | 1 | 49 | | WorkflowInstanceId = workflowInstanceId, |
| | 1 | 50 | | ActivityId = incident.ActivityId, |
| | 1 | 51 | | ActivityNodeId = incident.ActivityNodeId, |
| | 1 | 52 | | ActivityType = incident.ActivityType, |
| | 1 | 53 | | Message = incident.Message, |
| | 1 | 54 | | ExceptionType = incident.Exception?.Type?.FullName, |
| | 1 | 55 | | ExceptionMessage = incident.Exception?.Message, |
| | 1 | 56 | | Timestamp = incident.Timestamp |
| | 1 | 57 | | }; |
| | | 58 | | |
| | | 59 | | public JsonObject MapState(WorkflowInstance instance) => |
| | 1 | 60 | | formatter.RedactObject(new JsonObject |
| | 1 | 61 | | { |
| | 1 | 62 | | ["id"] = instance.Id, |
| | 1 | 63 | | ["status"] = instance.Status.ToString(), |
| | 1 | 64 | | ["subStatus"] = instance.SubStatus.ToString(), |
| | 1 | 65 | | ["input"] = AIGroundingJson.ToJsonObject(instance.WorkflowState.Input), |
| | 1 | 66 | | ["output"] = AIGroundingJson.ToJsonObject(instance.WorkflowState.Output), |
| | 1 | 67 | | ["properties"] = AIGroundingJson.ToJsonObject(instance.WorkflowState.Properties), |
| | 1 | 68 | | ["scheduledActivityCount"] = instance.WorkflowState.ScheduledActivities.Count, |
| | 1 | 69 | | ["bookmarkCount"] = instance.WorkflowState.Bookmarks.Count, |
| | 1 | 70 | | ["activityExecutionContextCount"] = instance.WorkflowState.ActivityExecutionContexts.Count |
| | 1 | 71 | | }); |
| | | 72 | | } |