We present a formalism of the dynamics of internal shocks in relativistic jets where the source has a time-dependent injection velocity and mass-loss rate . The variation of the injection velocity produces a two-shock wave structure , the working surface , that moves along the jet . This new formalism takes into account the fact that momentum conservation is not valid for relativistic flows where the relativistic mass lost by radiation must be taken into account , in contrast to the classic regime . We find analytic solutions for the working surface velocity and radiated energy for the particular case of a step function variability of the injection parameters . We model two cases : a pulse of fast material and a pulse of slow material ( with respect to the mean flow ) . Applying these models to gamma ray burst light curves , one can determine the ratio of the Lorentz factors \gamma _ { 2 } / \gamma _ { 1 } and the ratio of the mass-loss rates \dot { m } _ { 2 } / \dot { m } _ { 1 } of the upstream and downstream flows . As an example , we apply this model to the sources GRB 080413B and GRB 070318 and find the values of these ratios . Assuming a Lorentz factor \gamma _ { 1 } = 100 , we further estimate jet mass-loss rates between \dot { m } _ { 1 } \sim 10 ^ { -5 } -1 { M } _ { \odot } { yr } ^ { -1 } . We also calculate the fraction of the injected mass lost by radiation . For GRB 070318 this fraction is \sim 7 % . In contrast , for GRB 080413B this fraction is larger than 50 % ; in this case radiation losses clearly affect the dynamics of the internal shocks .