( value: unknown, )
| 202 | } |
| 203 | |
| 204 | function normalizeManagedState( |
| 205 | value: unknown, |
| 206 | ): ManagedAutonomyFlowState | undefined { |
| 207 | if ( |
| 208 | !value || |
| 209 | typeof value !== 'object' || |
| 210 | !('steps' in value) || |
| 211 | !Array.isArray((value as { steps: unknown[] }).steps) |
| 212 | ) { |
| 213 | return undefined |
| 214 | } |
| 215 | const parsed = value as Partial<ManagedAutonomyFlowState> |
| 216 | const steps = (parsed.steps ?? []) |
| 217 | .filter((step): step is ManagedAutonomyFlowStep => |
| 218 | Boolean( |
| 219 | step && |
| 220 | typeof step.stepId === 'string' && |
| 221 | typeof step.name === 'string' && |
| 222 | typeof step.prompt === 'string' && |
| 223 | typeof step.status === 'string', |
| 224 | ), |
| 225 | ) |
| 226 | .map(step => ({ |
| 227 | stepId: step.stepId, |
| 228 | name: step.name, |
| 229 | prompt: step.prompt, |
| 230 | status: step.status, |
| 231 | ...(step.waitFor ? { waitFor: step.waitFor } : {}), |
| 232 | ...(step.runId ? { runId: step.runId } : {}), |
| 233 | ...(step.startedAt != null ? { startedAt: step.startedAt } : {}), |
| 234 | ...(step.endedAt != null ? { endedAt: step.endedAt } : {}), |
| 235 | ...(step.error ? { error: step.error } : {}), |
| 236 | })) |
| 237 | if (steps.length === 0) { |
| 238 | return undefined |
| 239 | } |
| 240 | const currentStepIndex = Math.min( |
| 241 | Math.max(parsed.currentStepIndex ?? 0, 0), |
| 242 | steps.length - 1, |
| 243 | ) |
| 244 | return { |
| 245 | currentStepIndex, |
| 246 | steps, |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | function normalizeWaitState(value: unknown): AutonomyFlowWaitState | undefined { |
| 251 | if ( |
no test coverage detected