MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / normalizeManagedState

Function normalizeManagedState

src/utils/autonomyFlows.ts:204–248  ·  view source on GitHub ↗
(
  value: unknown,
)

Source from the content-addressed store, hash-verified

202}
203
204function 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
250function normalizeWaitState(value: unknown): AutonomyFlowWaitState | undefined {
251 if (

Callers 1

normalizeFlowRecordFunction · 0.85

Calls 1

maxMethod · 0.80

Tested by

no test coverage detected