|
1 | | -import type { Blueprint, BlueprintTask, TaskOutput, TaskParam } from '../types/blueprint-schema'; |
| 1 | +import type { Blueprint, Task, TaskOutput, TaskParam } from '../types/blueprint-schema'; |
2 | 2 | import { |
3 | 3 | isSystemTaskType, |
4 | 4 | SYSTEM_COMPOSITE_TASK_TYPE, |
@@ -31,14 +31,14 @@ export const SIMULATION_OPT_OUT_PARAM_NAME = '__sim_use_real_agent__'; |
31 | 31 |
|
32 | 32 | /** True if `params` carries the opt-out flag. Operates on a bare param list so both the |
33 | 33 | * derive-time rewrite and the authoring-tool panel (which only has `AuthorNodeData.params`, |
34 | | - * not a full `BlueprintTask`) can share one check. */ |
| 34 | + * not a full `Task`) can share one check. */ |
35 | 35 | export function isOptedOutParams(params: TaskParam[] | undefined): boolean { |
36 | 36 | return (params ?? []).some( |
37 | 37 | (p) => p.name === SIMULATION_OPT_OUT_PARAM_NAME && p.value === true, |
38 | 38 | ); |
39 | 39 | } |
40 | 40 |
|
41 | | -export function isOptedOutOfSimulation(task: BlueprintTask): boolean { |
| 41 | +export function isOptedOutOfSimulation(task: Task): boolean { |
42 | 42 | return isOptedOutParams(task.params); |
43 | 43 | } |
44 | 44 |
|
@@ -90,7 +90,7 @@ export class CompositeTaskNotSupportedError extends Error { |
90 | 90 | } |
91 | 91 | } |
92 | 92 |
|
93 | | -function rewriteTaskType(task: BlueprintTask): string { |
| 93 | +function rewriteTaskType(task: Task): string { |
94 | 94 | const { type } = task; |
95 | 95 | if (isSystemTaskType(type)) { |
96 | 96 | return type; |
@@ -121,15 +121,16 @@ function simulatedOutputParams(outputs: TaskOutput[] | undefined): TaskParam[] { |
121 | 121 | * Throws CompositeTaskNotSupportedError, naming the offending tasks, if the |
122 | 122 | * blueprint contains any `system.composite` task. |
123 | 123 | */ |
124 | | -export function deriveSimulationBlueprint(bp: Blueprint): Blueprint { |
125 | | - const compositeTaskIds = bp.tasks |
| 124 | +export function deriveSimulationBlueprint(bp: Blueprint): Blueprint & { tasks: Task[] } { |
| 125 | + const sourceTasks = bp.tasks ?? []; |
| 126 | + const compositeTaskIds = sourceTasks |
126 | 127 | .filter((task) => task.type === SYSTEM_COMPOSITE_TASK_TYPE) |
127 | 128 | .map((task) => task.id); |
128 | 129 | if (compositeTaskIds.length) { |
129 | 130 | throw new CompositeTaskNotSupportedError(compositeTaskIds); |
130 | 131 | } |
131 | 132 |
|
132 | | - const tasks: BlueprintTask[] = bp.tasks.map((task) => { |
| 133 | + const tasks: Task[] = sourceTasks.map((task) => { |
133 | 134 | const type = rewriteTaskType(task); |
134 | 135 | // Only tasks actually rewritten to simulation.* need their outputs carried as params — |
135 | 136 | // this also keeps the rewrite idempotent (re-deriving an already-derived task, whose type |
@@ -166,14 +167,14 @@ export function deriveSimulationBlueprint(bp: Blueprint): Blueprint { |
166 | 167 | * `__sim_out__` params from. Safe on a blueprint that was never derived — nothing matches, and |
167 | 168 | * it passes through unchanged. |
168 | 169 | */ |
169 | | -export function stripSimulationDerivation(bp: Blueprint): Blueprint { |
170 | | - const tasks: BlueprintTask[] = bp.tasks.map((task) => { |
| 170 | +export function stripSimulationDerivation(bp: Blueprint): Blueprint & { tasks: Task[] } { |
| 171 | + const tasks: Task[] = (bp.tasks ?? []).map((task) => { |
171 | 172 | const type = stripSimulationTypePrefix(task.type); |
172 | 173 | const params = (task.params ?? []).filter( |
173 | 174 | (param) => !param.name.startsWith(SIMULATED_OUTPUT_PARAM_PREFIX), |
174 | 175 | ); |
175 | 176 |
|
176 | | - const stripped: BlueprintTask = { ...task, type }; |
| 177 | + const stripped: Task = { ...task, type }; |
177 | 178 | if (params.length) { |
178 | 179 | stripped.params = params; |
179 | 180 | } else { |
|
0 commit comments