Skip to content

Commit ff4aa0d

Browse files
💾 Feat(Blueprint): 添加 VariableNode 类型与常量覆盖执行接口
- 新增 Variable 枚举值与 VariableNode 类(无端口浮游节点,用于无初始值变量声明) - 注册 JsonDerivedType 支持多态序列化 - IWorkflowService 新增带 constantOverrides 参数的 ExecuteBlockScriptAsync 重载
1 parent 1788c03 commit ff4aa0d

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

KitX Core Contracts/KitX.Core.Contract/Workflow/BlueprintModels.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ public enum BlueprintNodeType
8282
/// <summary>
8383
/// Pause execution node
8484
/// </summary>
85-
Pause
85+
Pause,
86+
87+
/// <summary>
88+
/// Variable declaration node (ConstBlock variables without initial values).
89+
/// A floating node with no ports — users can only change the data type.
90+
/// </summary>
91+
Variable
8692
}
8793

8894
/// <summary>
@@ -200,6 +206,7 @@ public class BlueprintPin
200206
[JsonDerivedType(typeof(SetNode), "Set")]
201207
[JsonDerivedType(typeof(PrintNode), "Print")]
202208
[JsonDerivedType(typeof(PauseNode), "Pause")]
209+
[JsonDerivedType(typeof(VariableNode), "Variable")]
203210
public abstract class BlueprintNode
204211
{
205212
/// <summary>
@@ -614,6 +621,40 @@ public PauseNode()
614621
);
615622
}
616623

624+
/// <summary>
625+
/// Variable node - ConstBlock variable without initial value.
626+
/// A floating node with no input/output ports. Users can change the data type
627+
/// but not the initial value. Type changes propagate to Get/Set nodes.
628+
/// </summary>
629+
public class VariableNode : BlueprintNode
630+
{
631+
/// <summary>
632+
/// Variable name
633+
/// </summary>
634+
public string VarName { get; set; } = string.Empty;
635+
636+
/// <summary>
637+
/// Variable type (e.g., "int", "double", "string", "bool")
638+
/// </summary>
639+
public string VarType { get; set; } = "int";
640+
641+
public VariableNode()
642+
{
643+
NodeType = BlueprintNodeType.Variable;
644+
Name = "Variable";
645+
InitializePinsFromDescriptor();
646+
}
647+
648+
public override NodeDescriptor GetDescriptor() => new(
649+
Width: 120, Height: 50,
650+
InputPins: [],
651+
OutputPins: [],
652+
DisplayName: "Variable"
653+
);
654+
655+
public override string GetDisplayTitle() => $"Var: {VarName}";
656+
}
657+
617658
/// <summary>
618659
/// Connection between two pins
619660
/// </summary>

KitX Core Contracts/KitX.Core.Contract/Workflow/IWorkflowService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,16 @@ Task<BlockScriptExecutionResult> ExecuteBlockScriptAsync(
147147
string sourceCode,
148148
List<HelperFunction> helperFunctions,
149149
System.Threading.CancellationToken cancellationToken = default);
150+
151+
/// <summary>
152+
/// Executes a block script from source code with helper functions and constant overrides.
153+
/// Constant overrides replace the DefaultValue on ConstBlock variables before execution.
154+
/// </summary>
155+
Task<BlockScriptExecutionResult> ExecuteBlockScriptAsync(
156+
string sourceCode,
157+
List<HelperFunction> helperFunctions,
158+
Dictionary<string, object?>? constantOverrides,
159+
System.Threading.CancellationToken cancellationToken = default);
150160
}
151161

152162
/// <summary>

0 commit comments

Comments
 (0)