forked from microsoft/semantic-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDaprStepInfo.cs
More file actions
76 lines (66 loc) · 2.72 KB
/
DaprStepInfo.cs
File metadata and controls
76 lines (66 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
namespace Microsoft.SemanticKernel;
/// <summary>
/// Contains information about a Step in a Dapr Process including it's state and edges.
/// </summary>
[KnownType(typeof(KernelProcessEdge))]
[KnownType(typeof(KernelProcessStepState))]
[KnownType(typeof(KernelProcessProxyMessage))]
[KnownType(typeof(DaprProcessInfo))]
[KnownType(typeof(DaprMapInfo))]
[KnownType(typeof(DaprProxyInfo))]
[JsonDerivedType(typeof(DaprProcessInfo))]
[JsonDerivedType(typeof(DaprMapInfo))]
[JsonDerivedType(typeof(DaprProxyInfo))]
public record DaprStepInfo
{
/// <summary>
/// The .Net type of the inner step.
/// </summary>
public required string InnerStepDotnetType { get; init; }
/// <summary>
/// The state of the Step.
/// </summary>
public required KernelProcessStepState State { get; init; }
/// <summary>
/// A read-only dictionary of output edges from the Step.
/// </summary>
public required Dictionary<string, List<KernelProcessEdge>> Edges { get; init; }
/// <summary>
/// Builds an instance of <see cref="KernelProcessStepInfo"/> from the current object.
/// </summary>
/// <returns>An instance of <see cref="KernelProcessStepInfo"/></returns>
/// <exception cref="KernelException"></exception>
public KernelProcessStepInfo ToKernelProcessStepInfo()
{
Type? innerStepType = Type.GetType(this.InnerStepDotnetType);
if (innerStepType is null)
{
throw new KernelException($"Unable to create inner step type from assembly qualified name `{this.InnerStepDotnetType}`");
}
if (!typeof(KernelProcessStep).IsAssignableFrom(innerStepType))
{
throw new KernelException($"Type '{this.InnerStepDotnetType}' is not a valid KernelProcessStep type.");
}
return new KernelProcessStepInfo(innerStepType, this.State, this.Edges);
}
/// <summary>
/// Initializes a new instance of the <see cref="DaprStepInfo"/> class from an instance of <see cref="KernelProcessStepInfo"/>.
/// </summary>
/// <returns>An instance of <see cref="DaprStepInfo"/></returns>
public static DaprStepInfo FromKernelStepInfo(KernelProcessStepInfo kernelStepInfo)
{
Verify.NotNull(kernelStepInfo, nameof(kernelStepInfo));
return new DaprStepInfo
{
InnerStepDotnetType = kernelStepInfo.InnerStepType.AssemblyQualifiedName!,
State = kernelStepInfo.State,
Edges = kernelStepInfo.Edges.ToDictionary(kvp => kvp.Key, kvp => new List<KernelProcessEdge>(kvp.Value)),
};
}
}