diff --git a/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FishSandwichStateProcessSuccess.json b/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FishSandwichStateProcessSuccess.json index d4b7a83024a0..55e8c7384e64 100644 --- a/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FishSandwichStateProcessSuccess.json +++ b/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FishSandwichStateProcessSuccess.json @@ -1,47 +1,55 @@ { + "$type": "Process", "stepsState": { "FriedFishWithStatefulStepsProcess": { + "$type": "Process", "stepsState": { "GatherFriedFishIngredientsWithStockStep": { - "state": { - "IngredientsStock": 4 - }, - "id": "32301d167a604f7bb1b69663d8feafe6", + "$type": "Step", + "id": "2908f8c88cf0476a8e0075c3a8020d5d", "name": "GatherFriedFishIngredientsWithStockStep", - "versionInfo": "GatherFishIngredient.V2" + "versionInfo": "GatherFishIngredient.V2", + "state": { + "IngredientsStock": 3 + } }, "CutFoodStep": { - "id": "3be68c614bc44bedb7bce0f002110968", + "$type": "Step", + "id": "014388cf0bbd41119b8730dfc4b0b459", "name": "CutFoodStep", "versionInfo": "CutFoodStep.V1" }, "FryFoodStep": { - "id": "5f80945fafec4a0bbeccf3ff23a8c1a1", + "$type": "Step", + "id": "c55af0425d864c4e97b6ae67bd715480", "name": "FryFoodStep", "versionInfo": "FryFoodStep.V1" } }, - "id": "c9d2e56dcc5a4b5ea73e05ae53635c90", + "id": "cab89a17aeae4b9a97568967dbf1ea47", "name": "FriedFishWithStatefulStepsProcess", "versionInfo": "FriedFishProcess.v1" }, "AddBunsStep": { - "id": "ef113fc874b0473c9c275827effe8dd8", + "$type": "Step", + "id": "35d09b83dea24ddf8e0c24fbe6a3746c", "name": "AddBunsStep", "versionInfo": "v1" }, "AddSpecialSauceStep": { - "id": "65a35f6dec6e45cab9e1b4df7d43a6bd", + "$type": "Step", + "id": "aa0d408976574afea94387e3da7ca111", "name": "AddSpecialSauceStep", "versionInfo": "v1" }, "ExternalFriedFishStep": { - "id": "ab186a81480a45249cfff9e0c56319b8", + "$type": "Step", + "id": "2eda38b8ee8745a4ab8b21f4fa01d173", "name": "ExternalFriedFishStep", "versionInfo": "v1" } }, - "id": "0de6d539-c1bf-44ad-816d-650231cd2034", + "id": "973b06f1-a522-4d2d-9e1c-ec45a07e275c", "name": "FishSandwichWithStatefulStepsProcess", "versionInfo": "FishSandwich.V1" } \ No newline at end of file diff --git a/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FishSandwichStateProcessSuccessLowStock.json b/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FishSandwichStateProcessSuccessLowStock.json index 746fe5933124..9af1d9c1763b 100644 --- a/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FishSandwichStateProcessSuccessLowStock.json +++ b/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FishSandwichStateProcessSuccessLowStock.json @@ -1,47 +1,55 @@ { + "$type": "Process", "stepsState": { "FriedFishWithStatefulStepsProcess": { + "$type": "Process", "stepsState": { "GatherFriedFishIngredientsWithStockStep": { + "$type": "Step", + "id": "2908f8c88cf0476a8e0075c3a8020d5d", + "name": "GatherFriedFishIngredientsWithStockStep", + "versionInfo": "GatherFishIngredient.V2", "state": { "IngredientsStock": 1 - }, - "id": "32301d167a604f7bb1b69663d8feafe6", - "name": "GatherFriedFishIngredientsWithStockStep", - "versionInfo": "GatherFishIngredient.V2" + } }, "CutFoodStep": { - "id": "3be68c614bc44bedb7bce0f002110968", + "$type": "Step", + "id": "014388cf0bbd41119b8730dfc4b0b459", "name": "CutFoodStep", "versionInfo": "CutFoodStep.V1" }, "FryFoodStep": { - "id": "5f80945fafec4a0bbeccf3ff23a8c1a1", + "$type": "Step", + "id": "c55af0425d864c4e97b6ae67bd715480", "name": "FryFoodStep", "versionInfo": "FryFoodStep.V1" } }, - "id": "c9d2e56dcc5a4b5ea73e05ae53635c90", + "id": "cab89a17aeae4b9a97568967dbf1ea47", "name": "FriedFishWithStatefulStepsProcess", "versionInfo": "FriedFishProcess.v1" }, "AddBunsStep": { - "id": "ef113fc874b0473c9c275827effe8dd8", + "$type": "Step", + "id": "35d09b83dea24ddf8e0c24fbe6a3746c", "name": "AddBunsStep", "versionInfo": "v1" }, "AddSpecialSauceStep": { - "id": "65a35f6dec6e45cab9e1b4df7d43a6bd", + "$type": "Step", + "id": "aa0d408976574afea94387e3da7ca111", "name": "AddSpecialSauceStep", "versionInfo": "v1" }, "ExternalFriedFishStep": { - "id": "ab186a81480a45249cfff9e0c56319b8", + "$type": "Step", + "id": "2eda38b8ee8745a4ab8b21f4fa01d173", "name": "ExternalFriedFishStep", "versionInfo": "v1" } }, - "id": "0de6d539-c1bf-44ad-816d-650231cd2034", + "id": "973b06f1-a522-4d2d-9e1c-ec45a07e275c", "name": "FishSandwichWithStatefulStepsProcess", "versionInfo": "FishSandwich.V1" } \ No newline at end of file diff --git a/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccess.json b/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccess.json index 8432c10a5ea1..d45815ddedf0 100644 --- a/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccess.json +++ b/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccess.json @@ -1,25 +1,29 @@ { + "$type": "Process", "stepsState": { "GatherFriedFishIngredientsWithStockStep": { - "state": { - "IngredientsStock": 4 - }, - "id": "7d492b6c1ea9404b8adb4c9b0c8f7589", + "$type": "Step", + "id": "92a4cda38c7248648b0aa7ffaaa57f21", "name": "GatherFriedFishIngredientsWithStockStep", - "versionInfo": "GatherFishIngredient.V2" + "versionInfo": "GatherFishIngredient.V2", + "state": { + "IngredientsStock": 3 + } }, "CutFoodStep": { - "id": "7c0d4dce18644abf92941ff2538806dc", + "$type": "Step", + "id": "7ace89e38e1c48b0b3a700b40d160c68", "name": "CutFoodStep", "versionInfo": "CutFoodStep.V1" }, "FryFoodStep": { - "id": "de06bfb72a3d4f05ba3b4fd4ceb43e1f", + "$type": "Step", + "id": "09bc39ba6d9745439c7c792b8dac0af7", "name": "FryFoodStep", "versionInfo": "FryFoodStep.V1" } }, - "id": "412f3ad1-d0fd-42f1-9c74-109cff87c75c", + "id": "669c5850-9efc-4585-b3f0-9291a4471887", "name": "FriedFishWithStatefulStepsProcess", "versionInfo": "FriedFishProcess.v1" } \ No newline at end of file diff --git a/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccessLowStock.json b/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccessLowStock.json index a89ab9121170..10372bc65077 100644 --- a/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccessLowStock.json +++ b/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccessLowStock.json @@ -1,25 +1,29 @@ { + "$type": "Process", "stepsState": { "GatherFriedFishIngredientsWithStockStep": { + "$type": "Step", + "id": "92a4cda38c7248648b0aa7ffaaa57f21", + "name": "GatherFriedFishIngredientsWithStockStep", + "versionInfo": "GatherFishIngredient.V2", "state": { "IngredientsStock": 1 - }, - "id": "7d492b6c1ea9404b8adb4c9b0c8f7589", - "name": "GatherFriedFishIngredientsWithStockStep", - "versionInfo": "GatherFishIngredient.V2" + } }, "CutFoodStep": { - "id": "7c0d4dce18644abf92941ff2538806dc", + "$type": "Step", + "id": "7ace89e38e1c48b0b3a700b40d160c68", "name": "CutFoodStep", "versionInfo": "CutFoodStep.V1" }, "FryFoodStep": { - "id": "de06bfb72a3d4f05ba3b4fd4ceb43e1f", + "$type": "Step", + "id": "09bc39ba6d9745439c7c792b8dac0af7", "name": "FryFoodStep", "versionInfo": "FryFoodStep.V1" } }, - "id": "412f3ad1-d0fd-42f1-9c74-109cff87c75c", + "id": "669c5850-9efc-4585-b3f0-9291a4471887", "name": "FriedFishWithStatefulStepsProcess", "versionInfo": "FriedFishProcess.v1" } \ No newline at end of file diff --git a/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccessNoStock.json b/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccessNoStock.json index 7b09024ce1ae..5c745ebe233f 100644 --- a/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccessNoStock.json +++ b/dotnet/samples/GettingStartedWithProcesses/Step03/ProcessesStates/FriedFishProcessStateSuccessNoStock.json @@ -1,25 +1,29 @@ { + "$type": "Process", "stepsState": { "GatherFriedFishIngredientsWithStockStep": { + "$type": "Step", + "id": "92a4cda38c7248648b0aa7ffaaa57f21", + "name": "GatherFriedFishIngredientsWithStockStep", + "versionInfo": "GatherFishIngredient.V2", "state": { "IngredientsStock": 0 - }, - "id": "7d492b6c1ea9404b8adb4c9b0c8f7589", - "name": "GatherFriedFishIngredientsWithStockStep", - "versionInfo": "GatherFishIngredient.V2" + } }, "CutFoodStep": { - "id": "7c0d4dce18644abf92941ff2538806dc", + "$type": "Step", + "id": "7ace89e38e1c48b0b3a700b40d160c68", "name": "CutFoodStep", "versionInfo": "CutFoodStep.V1" }, "FryFoodStep": { - "id": "de06bfb72a3d4f05ba3b4fd4ceb43e1f", + "$type": "Step", + "id": "09bc39ba6d9745439c7c792b8dac0af7", "name": "FryFoodStep", "versionInfo": "FryFoodStep.V1" } }, - "id": "412f3ad1-d0fd-42f1-9c74-109cff87c75c", + "id": "669c5850-9efc-4585-b3f0-9291a4471887", "name": "FriedFishWithStatefulStepsProcess", "versionInfo": "FriedFishProcess.v1" } \ No newline at end of file diff --git a/dotnet/samples/GettingStartedWithProcesses/Utilities/ProcessStateMetadataUtilities.cs b/dotnet/samples/GettingStartedWithProcesses/Utilities/ProcessStateMetadataUtilities.cs index e8d42de21efc..018b98a378e2 100644 --- a/dotnet/samples/GettingStartedWithProcesses/Utilities/ProcessStateMetadataUtilities.cs +++ b/dotnet/samples/GettingStartedWithProcesses/Utilities/ProcessStateMetadataUtilities.cs @@ -31,7 +31,7 @@ public static void DumpProcessStateMetadataLocally(KernelProcessStateMetadata pr using StreamReader reader = new(filepath); var content = reader.ReadToEnd(); - return JsonSerializer.Deserialize(content); + return JsonSerializer.Deserialize(content, s_jsonOptions); } private static string GetRepositoryProcessStateFilepath(string jsonRelativePath, bool checkFilepathExists = false) @@ -62,7 +62,7 @@ private static void StoreProcessStateLocally(KernelProcessStateMetadata processS throw new KernelException($"Filepath for process {processStateInfo.Name} does not have .json extension"); } - var content = JsonSerializer.Serialize(processStateInfo, s_jsonOptions); + var content = JsonSerializer.Serialize(processStateInfo, s_jsonOptions); Console.WriteLine($"Process State: \n{content}"); Console.WriteLine($"Saving Process State Locally: \n{Path.GetFullPath(fullFilepath)}"); File.WriteAllText(fullFilepath, content); diff --git a/dotnet/src/Experimental/Process.Abstractions/Models/KernelProcessStateMetadata.cs b/dotnet/src/Experimental/Process.Abstractions/Models/KernelProcessStateMetadata.cs index 73e46faadf54..8a6355b4b423 100644 --- a/dotnet/src/Experimental/Process.Abstractions/Models/KernelProcessStateMetadata.cs +++ b/dotnet/src/Experimental/Process.Abstractions/Models/KernelProcessStateMetadata.cs @@ -9,12 +9,12 @@ namespace Microsoft.SemanticKernel.Process.Models; /// /// Process state used for State Persistence serialization /// -public record class KernelProcessStateMetadata : KernelProcessStepStateMetadata +public sealed record class KernelProcessStateMetadata : KernelProcessStepStateMetadata { /// /// Process State of Steps if provided /// [DataMember] [JsonPropertyName("stepsState")] - public Dictionary? StepsState { get; set; } + public Dictionary? StepsState { get; set; } = null; } diff --git a/dotnet/src/Experimental/Process.Abstractions/Models/KernelProcessStepStateMetadata.cs b/dotnet/src/Experimental/Process.Abstractions/Models/KernelProcessStepStateMetadata.cs index 55284a1bd403..7b92e5e4dd90 100644 --- a/dotnet/src/Experimental/Process.Abstractions/Models/KernelProcessStepStateMetadata.cs +++ b/dotnet/src/Experimental/Process.Abstractions/Models/KernelProcessStepStateMetadata.cs @@ -2,12 +2,16 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; +using Microsoft.SemanticKernel.Process.Internal; namespace Microsoft.SemanticKernel.Process.Models; /// /// Step state used for State Persistence serialization /// +[JsonPolymorphic(TypeDiscriminatorPropertyName = "$type", UnknownDerivedTypeHandling = JsonUnknownDerivedTypeHandling.FallBackToNearestAncestor)] +[JsonDerivedType(typeof(KernelProcessStepStateMetadata), typeDiscriminator: nameof(ProcessConstants.SupportedComponents.Step))] +[JsonDerivedType(typeof(KernelProcessStateMetadata), typeDiscriminator: nameof(ProcessConstants.SupportedComponents.Process))] public record class KernelProcessStepStateMetadata { /// @@ -33,17 +37,11 @@ public record class KernelProcessStepStateMetadata [DataMember] [JsonPropertyName("versionInfo")] public string? VersionInfo { get; init; } = null; -} -/// -/// Step state used for State Persistence serialization for stateful steps -/// -public record class KernelProcessStepStateMetadata : KernelProcessStepStateMetadata where TState : class, new() -{ /// - /// The user-defined state object associated with the Step. + /// The user-defined state object associated with the Step (if the step is stateful) /// [DataMember] [JsonPropertyName("state")] - public TState? State { get; set; } = null; + public object? State { get; set; } = null; } diff --git a/dotnet/src/Experimental/Process.Core/Internal/EndStep.cs b/dotnet/src/Experimental/Process.Core/Internal/EndStep.cs index 22c29a4839ab..a576e43b2e15 100644 --- a/dotnet/src/Experimental/Process.Core/Internal/EndStep.cs +++ b/dotnet/src/Experimental/Process.Core/Internal/EndStep.cs @@ -30,12 +30,7 @@ internal override Dictionary GetFunctionMetadata return []; } - internal override KernelProcessStepInfo BuildStep() - { - return this.BuildStep(null); - } - - internal override KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata? stateMetadata) + internal override KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata? stateMetadata = null) { // The end step has no state. return new KernelProcessStepInfo(typeof(KernelProcessStepState), new KernelProcessStepState(ProcessConstants.EndStepName, version: ProcessConstants.InternalStepsVersion), []); diff --git a/dotnet/src/Experimental/Process.Core/Internal/KernelProcessStateMetadataExtension.cs b/dotnet/src/Experimental/Process.Core/Internal/KernelProcessStateMetadataExtension.cs index 87d89a4ebcdc..701cbd157dc9 100644 --- a/dotnet/src/Experimental/Process.Core/Internal/KernelProcessStateMetadataExtension.cs +++ b/dotnet/src/Experimental/Process.Core/Internal/KernelProcessStateMetadataExtension.cs @@ -70,7 +70,7 @@ private static KernelProcessStateMetadata SanitizeProcessStateMetadata(KernelPro // version mismatch - check if migration logic in place if (step is ProcessBuilder subprocessBuilder) { - var sanitizedStepState = SanitizeProcessStateMetadata(savedStateMetadata, subprocessBuilder.Steps.ToList()); + var sanitizedStepState = SanitizeProcessStateMetadata((KernelProcessStateMetadata)savedStateMetadata, subprocessBuilder.Steps.ToList()); sanitizedStateMetadata.StepsState[step.Name] = sanitizedStepState; } else if (false) @@ -80,7 +80,7 @@ private static KernelProcessStateMetadata SanitizeProcessStateMetadata(KernelPro else { // no compatible state found, migrating id only - sanitizedStateMetadata.StepsState[step.Name] = new KernelProcessStateMetadata() + sanitizedStateMetadata.StepsState[step.Name] = new KernelProcessStepStateMetadata() { Name = step.Name, Id = step.Id, diff --git a/dotnet/src/Experimental/Process.Core/ProcessBuilder.cs b/dotnet/src/Experimental/Process.Core/ProcessBuilder.cs index 984e70591a15..e8ed21744da1 100644 --- a/dotnet/src/Experimental/Process.Core/ProcessBuilder.cs +++ b/dotnet/src/Experimental/Process.Core/ProcessBuilder.cs @@ -96,31 +96,15 @@ internal override Dictionary GetFunctionMetadata /// /// State to apply to the step on the build process /// - internal override KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata? stateMetadata) + internal override KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata? stateMetadata = null) { // The step is a, process so we can return the step info directly. if (stateMetadata is KernelProcessStateMetadata processState) { - return this.BuildStep(processState); + return this.Build(processState); } - return this.BuildStep(); - } - - /// - /// Build the subprocess step - /// - /// State to apply to the step on the build process - /// - private KernelProcess BuildStep(KernelProcessStateMetadata? stateMetadata) - { - // The step is a process so we can return the step info directly. - return this.Build(stateMetadata); - } - - internal override KernelProcessStepInfo BuildStep() - { - return this.Build(null); + return this.Build(); } #region Public Interface diff --git a/dotnet/src/Experimental/Process.Core/ProcessStepBuilder.cs b/dotnet/src/Experimental/Process.Core/ProcessStepBuilder.cs index 9ecdb6c81c2a..9cc9aabcbac0 100644 --- a/dotnet/src/Experimental/Process.Core/ProcessStepBuilder.cs +++ b/dotnet/src/Experimental/Process.Core/ProcessStepBuilder.cs @@ -82,14 +82,8 @@ public ProcessStepEdgeBuilder OnFunctionError(string functionName) /// /// Builds the step with step state /// - /// an instance of . - internal abstract KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata? stateMetadata); - - /// - /// Builds the step. - /// - /// an instance of . - internal abstract KernelProcessStepInfo BuildStep(); + /// an instance of . + internal abstract KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata? stateMetadata = null); /// /// Links the output of the current step to the an input of another step via the specified event type. @@ -225,16 +219,11 @@ internal ProcessStepBuilder(string? name = null, object? initialState = default) this._initialState = initialState; } - internal override KernelProcessStepInfo BuildStep() - { - return this.BuildStep(null); - } - /// /// Builds the step with a state if provided /// /// An instance of - internal override KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata? stateMetadata) + internal override KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata? stateMetadata = null) { KernelProcessStepState? stateObject = null; KernelProcessStepMetadataAttribute stepMetadataAttributes = KernelProcessStepMetadataFactory.ExtractProcessStepMetadataFromType(typeof(TStep)); @@ -249,18 +238,15 @@ internal override KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata var stateType = typeof(KernelProcessStepState<>).MakeGenericType(userStateType); Verify.NotNull(stateType); - if (stateMetadata != null && stateMetadata.State != null) + if (stateMetadata != null && stateMetadata.State != null && stateMetadata.State is JsonElement jsonState) { - if (stateMetadata.State is JsonElement jsonState) + try + { + this._initialState = jsonState.Deserialize(userStateType); + } + catch (JsonException) { - try - { - this._initialState = jsonState.Deserialize(userStateType); - } - catch (JsonException) - { - throw new KernelException($"The initial state provided for step {this.Name} is not of the correct type. The expected type is {userStateType.Name}."); - } + throw new KernelException($"The initial state provided for step {this.Name} is not of the correct type. The expected type is {userStateType.Name}."); } } diff --git a/dotnet/src/Experimental/Process.Runtime.Dapr/Actors/ProcessActor.cs b/dotnet/src/Experimental/Process.Runtime.Dapr/Actors/ProcessActor.cs index ba109bf83b7a..0d033659399d 100644 --- a/dotnet/src/Experimental/Process.Runtime.Dapr/Actors/ProcessActor.cs +++ b/dotnet/src/Experimental/Process.Runtime.Dapr/Actors/ProcessActor.cs @@ -442,7 +442,7 @@ private async Task IsEndMessageSentAsync() /// private async Task ToDaprProcessInfoAsync() { - var processState = new KernelProcessState(this.Name, this.Id.GetId()); + var processState = new KernelProcessState(this.Name, this._stepState!.Version, this.Id.GetId()); var stepTasks = this._steps.Select(step => step.ToDaprStepInfoAsync()).ToList(); var steps = await Task.WhenAll(stepTasks).ConfigureAwait(false); return new DaprProcessInfo { InnerStepDotnetType = this._process!.InnerStepDotnetType, Edges = this._process!.Edges, State = processState, Steps = [.. steps] }; diff --git a/dotnet/src/Experimental/Process.UnitTests/Core/ProcessStepBuilderTests.cs b/dotnet/src/Experimental/Process.UnitTests/Core/ProcessStepBuilderTests.cs index a245c9e73c4d..07c4802c8731 100644 --- a/dotnet/src/Experimental/Process.UnitTests/Core/ProcessStepBuilderTests.cs +++ b/dotnet/src/Experimental/Process.UnitTests/Core/ProcessStepBuilderTests.cs @@ -235,12 +235,7 @@ private sealed class TestProcessStepBuilder : ProcessStepBuilder { public TestProcessStepBuilder(string name) : base(name) { } - internal override KernelProcessStepInfo BuildStep() - { - return this.BuildStep(null); - } - - internal override KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata? stateMetadata = null) + internal override KernelProcessStepInfo BuildStep(KernelProcessStepStateMetadata? stateMetadata = null) { return new KernelProcessStepInfo(typeof(TestProcessStepBuilder), new KernelProcessStepState(this.Name, version: "v1", id: this.Id), []); } diff --git a/dotnet/src/Experimental/Process.Utilities.UnitTests/CloneTests.cs b/dotnet/src/Experimental/Process.Utilities.UnitTests/CloneTests.cs index 7f49608c72d1..e1f8957038cd 100644 --- a/dotnet/src/Experimental/Process.Utilities.UnitTests/CloneTests.cs +++ b/dotnet/src/Experimental/Process.Utilities.UnitTests/CloneTests.cs @@ -108,8 +108,8 @@ public void VerifyCloneNestedProcessTest() { // Arrange KernelProcessStepInfo step = new(typeof(KernelProcessStep), new(nameof(VerifyCloneNestedProcessTest), "teststep"), []); - KernelProcess subProcess = new(new(nameof(VerifyCloneNestedProcessTest), "inner"), [step], CreateTestEdges()); - KernelProcess source = new(new(nameof(VerifyCloneNestedProcessTest), "outer"), [subProcess], []); + KernelProcess subProcess = new(new(nameof(VerifyCloneNestedProcessTest), "v2", "inner"), [step], CreateTestEdges()); + KernelProcess source = new(new(nameof(VerifyCloneNestedProcessTest), "v1", "outer"), [subProcess], []); // Act KernelProcess copy = source.CloneProcess(NullLogger.Instance); @@ -122,6 +122,7 @@ private static void VerifyProcess(KernelProcess expected, KernelProcess actual) { Assert.Equal(expected.State.Id, actual.State.Id); Assert.Equal(expected.State.Name, actual.State.Name); + Assert.Equal(expected.State.Version, actual.State.Version); Assert.Equal(expected.InnerStepType, actual.InnerStepType); Assert.Equivalent(expected.Edges, actual.Edges); foreach (var (expectedStep, actualStep) in expected.Steps.Zip(actual.Steps)) diff --git a/dotnet/src/InternalUtilities/process/Abstractions/KernelProcessStateMetadataFactory.cs b/dotnet/src/InternalUtilities/process/Abstractions/KernelProcessStateMetadataFactory.cs index 593346e54006..50c8f3011aa4 100644 --- a/dotnet/src/InternalUtilities/process/Abstractions/KernelProcessStateMetadataFactory.cs +++ b/dotnet/src/InternalUtilities/process/Abstractions/KernelProcessStateMetadataFactory.cs @@ -9,13 +9,13 @@ internal static class ProcessStateMetadataFactory /// Captures Kernel Process Step State into /// /// - private static KernelProcessStateMetadata StepInfoToProcessStateMetadata(KernelProcessStepInfo stepInfo) + private static KernelProcessStepStateMetadata StepInfoToProcessStateMetadata(KernelProcessStepInfo stepInfo) { - KernelProcessStateMetadata metadata = new() + KernelProcessStepStateMetadata metadata = new() { Name = stepInfo.State.Name, Id = stepInfo.State.Id, - VersionInfo = stepInfo.State.Version, + VersionInfo = stepInfo.State.Version }; if (stepInfo.InnerStepType.TryGetSubtypeOfStatefulStep(out var genericStateType) && genericStateType != null) @@ -52,20 +52,18 @@ public static KernelProcessStateMetadata KernelProcessToProcessStateMetadata(Ker KernelProcessStateMetadata stepEventMetadata = new(); if (step is KernelProcess stepSubprocess) { - stepEventMetadata = KernelProcessToProcessStateMetadata(stepSubprocess); + metadata.StepsState.Add(step.State.Name, KernelProcessToProcessStateMetadata(stepSubprocess)); } else { - stepEventMetadata = StepInfoToProcessStateMetadata(step); + metadata.StepsState.Add(step.State.Name, StepInfoToProcessStateMetadata(step)); } - - metadata.StepsState.Add(step.State.Name, stepEventMetadata); } return metadata; } - public static KernelProcessStateMetadata ToProcessStateMetadata(this KernelProcessStepInfo stepInfo) + public static KernelProcessStepStateMetadata ToProcessStateMetadata(this KernelProcessStepInfo stepInfo) { if (stepInfo is KernelProcess subprocess) { diff --git a/dotnet/src/InternalUtilities/process/Abstractions/ProcessConstants.cs b/dotnet/src/InternalUtilities/process/Abstractions/ProcessConstants.cs index be691d3ed1f2..442848337952 100644 --- a/dotnet/src/InternalUtilities/process/Abstractions/ProcessConstants.cs +++ b/dotnet/src/InternalUtilities/process/Abstractions/ProcessConstants.cs @@ -17,4 +17,14 @@ internal static class ProcessConstants /// Version for state of internal steps /// public const string InternalStepsVersion = "v0"; + + /// + /// Enum containing the name of internal components. + /// Used for serialization purposes. + /// + public enum SupportedComponents + { + Step = 0, + Process = 1, + } }