const PLAN_ITEM_STATUSES = new Set(['pending', 'in_progress', 'completed']);
/**
 * Parses update_plan tool output into the agent's active plan state.
 */
export class AgentPlanStateParser {
    static parse(args) {
        if (!args.output || typeof args.output !== 'object' || Array.isArray(args.output)) {
            return undefined;
        }
        const candidate = args.output;
        if (!Array.isArray(candidate.plan)) {
            return undefined;
        }
        const items = candidate.plan.flatMap((item) => AgentPlanStateParser.parseItem(item));
        if (items.length === 0) {
            return undefined;
        }
        return {
            explanation: typeof candidate.explanation === 'string' ? candidate.explanation : undefined,
            items,
        };
    }
    static parseItem(item) {
        if (!item || typeof item !== 'object' || Array.isArray(item)) {
            return [];
        }
        const step = typeof item.step === 'string' ? item.step : undefined;
        const status = item.status;
        if (!step || typeof status !== 'string' || !PLAN_ITEM_STATUSES.has(status)) {
            return [];
        }
        return [{ step, status: status }];
    }
}
//# sourceMappingURL=plan-state-parser.js.map